home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 022 / lemacs / hp150.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  7KB  |  339 lines

  1. /*
  2.  * The routines in this file provide support for HP150 screens
  3.  * and routines to access the Keyboard through KEYCODE mode.
  4.  * It compiles into nothing if not an HP150 screen device.
  5.  * added by Daniel Lawrence
  6.  */
  7.  
  8. #define    termdef    1            /* don't define "term" external */
  9.  
  10. #include        <stdio.h>
  11. #include        "estruct.h"
  12. #include    "edef.h"
  13.  
  14. #if     HP150
  15.  
  16. #include    <dos.h>
  17.  
  18. #define NROW    24                      /* Screen size.                 */
  19. #define NCOL    80                      /* Edit if you want to.         */
  20. #define    MARGIN    8            /* size of minimim margin and    */
  21. #define    SCRSIZ    64            /* scroll size for extended lines */
  22. #define BEL     0x07                    /* BEL character.               */
  23. #define ESC     0x1B                    /* ESC character.               */
  24.  
  25. extern  int     openhp();               /* Forward references.          */
  26. extern  int     ttgetc();
  27. extern  int     ttputc();
  28. extern  int     ttflush();
  29. extern  int     closehp();
  30. extern  int     hp15move();
  31. extern  int     hp15eeol();
  32. extern  int     hp15eeop();
  33. extern  int     hp15beep();
  34. extern    int    gethpkey();
  35. extern    int    hp15rev();
  36.  
  37. /* weird to ascii translation table */
  38.  
  39. char trans[][2] = {
  40.     0x24,    9,    /* tab */
  41.     0x25,    13,    /* ret */
  42.     0x27,    8,    /* backspace */
  43.     0x30,    48,    /* zero */
  44.     0x31,    49,    /* one */
  45.     0x32,    50,    /* two */
  46.     0x33,    51,    /* three */
  47.     0x34,    52,    /* four */
  48.     0x35,    53,    /* five */
  49.     0x36,    54,    /* six */
  50.     0x37,    55,    /* seven */
  51.     0x38,    56,    /* eight */
  52.     0x39,    57,    /* nine */
  53.     0x50,    13,    /* enter */
  54.     0x54,    27,    /* break -> ESC */
  55.     0x55,    27,    /* esc */
  56.     0x58,    24,    /* stop -> ^X */
  57.     0x70,    45,    /* N-minus */
  58.     0x71,    42,    /* N-asterisk */
  59.     0x72,    43,    /* N-plus */
  60.     0x73,    47,    /* N-slash */
  61.     0x74,    44,    /* N-comma */
  62.     0x75,    13,    /* N-enter */
  63.     0x76,    9,    /* N-tab */
  64.     0x77,    46    /* N-period */
  65. };
  66.  
  67. #define NTRANS    sizeof(trans) / 2
  68.  
  69. union REGS r;        /* register set for bios and dos (AGIOS) calls */
  70. int capslock = 0;    /* caps lock flag */
  71.  
  72. /*
  73.  * Standard terminal interface dispatch table. Most of the fields point into
  74.  * "termio" code.
  75.  */
  76. TERM    term    = {
  77.         NROW-1,
  78.         NCOL,
  79.     MARGIN,
  80.     SCRSIZ,
  81.     openhp,
  82.         closehp,
  83.     gethpkey,
  84.         ttputc,
  85.         ttflush,
  86.         hp15move,
  87.         hp15eeol,
  88.         hp15eeop,
  89.         hp15beep,
  90.         hp15rev
  91. };
  92.  
  93. hp15move(row, col)
  94. {
  95.         ttputc(ESC);
  96.         ttputc('&');
  97.         ttputc('a');
  98.         hp15parm(col);
  99.         ttputc('c');
  100.         hp15parm(row);
  101.         ttputc('R');
  102. }
  103.  
  104. hp15eeol()
  105. {
  106.         ttputc(ESC);
  107.         ttputc('K');
  108. }
  109.  
  110. hp15eeop()
  111. {
  112.         ttputc(ESC);
  113.         ttputc('J');
  114. }
  115.  
  116. hp15rev(status)        /* change the reverse video status */
  117.  
  118. int status;    /* TRUE = on, FALSE = off */
  119.  
  120. {
  121.     ttputc(ESC);
  122.     ttputc('&');
  123.     ttputc('d');
  124.     ttputc(status ? 'B': '@');
  125. }
  126.  
  127. hp15beep()
  128. {
  129.         ttputc(BEL);
  130.         ttflush();
  131. }
  132.  
  133. hp15parm(n)
  134. register int    n;
  135. {
  136.         register int    q;
  137.  
  138.         q = n/10;
  139.         if (q != 0)
  140.                 hp15parm(q);
  141.         ttputc((n%10) + '0');
  142. }
  143.  
  144.  
  145. gethpkey()    /* get a key from the HP keyboard while in keycode mode */
  146.  
  147. {
  148.     static int keepflag = 0;    /* kept ahead char flag */
  149.     static int keepchar = 0;    /* kept ehead flag */
  150.     int c;
  151.     int devid;            /* device ID */
  152.     int ctype;            /* type of character gotten */
  153.     int shiftb;            /* state of shift keys */
  154.     int i;
  155.     
  156.     /* if we are in an extended char sequence, finish it */
  157.     if (keepflag != 0) {
  158.         keepflag = 0;
  159.         return(keepchar);
  160.     }
  161.  
  162.     /* grab the next 4 char sequence */
  163. next:    shiftb = ttgetc();
  164.     devid = ttgetc();
  165.     c = ttgetc();
  166.     ttgetc();        /* skip null byte */
  167.     
  168.     /* make sure we are from the keyboard */
  169.     if (devid != 192)
  170.         goto next;
  171.  
  172.     /* if normal ascii, return it */
  173.     if ((shiftb & 0x80) == 0) {
  174.         if (capslock && c >= 'a' && c <= 'z')
  175.             c -= 32;
  176.         return(c);
  177.     }
  178.  
  179.     /* check specifically for the caps lock key */
  180.     if (c == 0x56) {
  181.         capslock = ~capslock;
  182.         goto next;
  183.     }
  184.  
  185.     /* check to see if it needs translation */
  186.     for (i=0; i < NTRANS; i++)
  187.         if (trans[i][0] == c)
  188.             return((int)trans[i][1]);
  189.  
  190.     /* other wise, shove it in the keep char and return the leadin code */
  191.     keepchar = c;
  192.     keepflag = 1;
  193.     return(0);
  194. }
  195.  
  196. openhp()        /* open the HP150 keyboard for input */
  197.  
  198. {
  199.     revexist = TRUE;
  200.  
  201.     /* define key charectoristics with AGIOS call (0, 40) */
  202.     defkey();
  203.  
  204.     /* Turn on RAW mode with MSDOS call 44h */
  205.     rawon();
  206.  
  207.     /* Turn off Control-C checking  MS-DOS 33h */
  208.     ckeyoff();
  209.  
  210.     /* Turn on keycode mode with AGIOS call (0,43) */
  211.     keycon();
  212. }
  213.  
  214. closehp()        /* close the HP150 keyboard for input */
  215.  
  216. {
  217.     /* define key charectoristics with AGIOS call (0, 40) */
  218.     undefkey();
  219.     
  220.     /* Turn off RAW mode with MSDOS call 44h */
  221.     rawoff();
  222.  
  223.     /* Turn on Control-C checking  MS-DOS 33h */
  224.     ckeyon();
  225.  
  226.     /* Turn off keycode mode with AGIOS call (0,43) */
  227.     keycoff();
  228. }
  229.  
  230. rawon()        /* put the HP150 keyboard into RAW mode */
  231.  
  232. {
  233.     /* get the IO control info */
  234.  
  235.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  236.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  237.     intdos(&r, &r);        /* go fer it */
  238.  
  239.     r.h.dh = 0;        /* clear high byte for put */
  240.     r.h.dl |= 0x20;        /* set raw bit */
  241.  
  242.     /* and put it back */
  243.  
  244.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  245.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  246.     intdos(&r, &r);        /* go fer it */
  247. }
  248.  
  249. rawoff()    /* put the HP150 keyboard into COOKED mode */
  250.  
  251. {
  252.     /* get the IO control info */
  253.  
  254.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  255.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  256.     intdos(&r, &r);        /* go fer it */
  257.  
  258.     r.h.dh = 0;        /* clear high byte for put */
  259.     r.h.dl &= 0xdf;        /* set raw bit */
  260.  
  261.     /* and put it back */
  262.  
  263.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  264.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  265.     intdos(&r, &r);        /* go fer it */
  266. }
  267.  
  268.  
  269. ckeyoff()    /* turn control-C trapping off */
  270.  
  271. {
  272.     r.h.ah = 0x33;    /* ctrl-break check */
  273.     r.h.al = 1;    /* set the state of the ctrl-break check */
  274.     r.h.dl = 0;    /* turn it off */
  275.     intdos(&r, &r);
  276. }
  277.  
  278. ckeyon()    /* turn control-C trapping on */
  279.  
  280. {
  281.     r.h.ah = 0x33;    /* ctrl-break check */
  282.     r.h.al = 1;    /* set the state of the ctrl-break check */
  283.     r.h.dl = 1;    /* turn it on */
  284.     intdos(&r, &r);
  285. }
  286.  
  287. agios(buf, len)    /* perform an AGIOS call */
  288.  
  289. char *buf;    /* sequence of bytes in command */
  290. int len;    /* length of command in bytes */
  291.  
  292. {
  293.     r.x.ax = 0x4403;    /* I/O ctrl write */
  294.     r.x.bx = 1;        /* console handle */
  295.     r.x.cx = len;        /* buffer length */
  296.     r.x.dx = (unsigned)buf;    /* buffer address */
  297.     return(intdos(&r, &r));    /* do it */
  298. }
  299.  
  300. keycon()    /* turn keycode mode on */
  301.  
  302. {
  303.     static char cmd[] = {43, 0, 1};
  304.  
  305.     return(agios(&cmd[0], 3));
  306. }
  307.  
  308. keycoff()    /* turn keycode mode off */
  309.  
  310. {
  311.     static char cmd[] = {43, 0, 0};
  312.  
  313.     return(agios(&cmd[0], 3));
  314. }
  315.  
  316. defkey()    /* change all special keys to intercept mode */
  317.  
  318. {
  319.     static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
  320.  
  321.     return(agios(&cmd[0], 6));
  322. }
  323.  
  324. undefkey()    /* change all special keys to intercept mode */
  325.  
  326. {
  327.     static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
  328.  
  329.     return(agios(&cmd[0], 6));
  330. }
  331.  
  332. #else
  333.  
  334. h15hello()
  335.  
  336. {
  337. }
  338. #endif
  339.